const { completedQuestionsModel } = require("../models/completedQuestionsModel");
const { userModel } = require("../models/userModel");
//找到用户在某场考试的完成答案（前端考试解析页面拿到result数组渲染所有题目，题号）
async function getResult(req, res, next){
    let {test_id,user_id}=req.query;
    console.log(req.query);
    let result=await completedQuestionsModel.find({test_id,user_id}).populate('test_id').populate('user_id').populate('questions_id');
    if(result.length>0){
        res.send({
            result,
            code:200
        })
    }else{
        res.send({
            message:"未找到该考生考试信息",
            code:-1
        })
    }
};


// 获取前端考试交卷后提交的数据。。。。。。。。。。。。
async function getSubmitTest(req, res, next){
    let {str}=req.body;
    let completedQuestions=JSON.parse(str);
    for(var i of completedQuestions){
        let result = await  completedQuestionsModel.create(i)
    };
    res.send({code:200});
}


module.exports={getResult,getSubmitTest}